import os
import shutil

def createFolders():
  path = '/Users/putao/Desktop/git/python/practice/10/10.4.2'

  if not os.path.exists(path):
    os.mkdir(path)
    createFolderByPath(path)
  else:
    print('该目录已经存在，先删除再创建！')
    shutil.rmtree(path)
    os.mkdir(path)
    createFolderByPath(path)

def createFolderByPath(name):
  number = int(input('请输入需要生成的文件夹个数：'))
  i = 0
  while i < number:
    path = name + '/' + str(i)
    if not os.path.exists(path):
      os.mkdir(path)
      print('文件夹' + str(i+1) + ' 创建成功！')
    else:
      print('文件夹已经存在')
    i += 1

createFolders()